home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!news
- From: ishky@ix.netcom.com(Andrew Heiz )
- Newsgroups: comp.lang.c
- Subject: Why does my program do this?
- Date: 1 Apr 1996 04:22:58 GMT
- Organization: Netcom
- Message-ID: <4jnln2$95j@dfw-ixnews3.ix.netcom.com>
- NNTP-Posting-Host: ix-li2-16.ix.netcom.com
- X-NETCOM-Date: Sun Mar 31 10:22:58 PM CST 1996
-
- Hi again,
-
- There have been so many helpful readers out there here is another
- question for you.
-
- I've declared an 2 dimentional array:
-
- char scores[STUDENT][5];
-
- I am entering the scores in 2 for loops like this:
-
- for (i=0; i <= students-1; i=i+1)
- {
- for (j=0; j <= tests-1; j=j+1)
- {
- gets(&scores[i][j];
- }
- }
-
- I print out the scores in the same type of loop structure:
-
- for (i=0; i <= students-1; i=i+1)
- {
- printf("Scores for student %d",i+1);
- for (j=0; j <= tests-1; j=j+1)
- {
- printf("\tGrade %d: %s",j+1,scores[i][j]);
- }
- }
-
- I am getting (if you don't already know this):
-
- Scores for student 1: Grade 1: 999991 Grade 2: 99991 Grade
- 3: 9991 Grade 4: 991 Grade 5: 91
-
- Is my data being mangled some how in the data entry? I've tried just
- printing out 1 array element or not using the loop and naming each
- element but nothing seems to work.
-
- If you can explain why this is happening and how to fix it my computer
- would be greatful. I've been making some awful threats at it today. It
- must be something simple I'm overlooking.
-
- Thanks again if you have helped me in the past and with this question.
-
- Please post or e-mail your response.
-
- Happy coding,
- Andy
- e-mail ishky@ix.netcom.com
-